Move suggestion logic into generate_targets()
authorRyan Quattlebaum <ryan.quattlebaum@icloud.com>
Fri, 18 Mar 2016 16:00:22 +0000 (12:00 -0400)
committerRyan Quattlebaum <ryan.quattlebaum@icloud.com>
Fri, 18 Mar 2016 16:00:22 +0000 (12:00 -0400)
Cargo.lock
src/cargo/ops/cargo_compile.rs

index f5e59849d515290c29dcce5f8f7fb112f45374d7..fda1b5725f021a2547ab4d22592424e5085ec208 100644 (file)
@@ -17,7 +17,7 @@ dependencies = [
  "hamcrest 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "regex 0.1.48 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -161,7 +161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -205,7 +205,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "libgit2-sys"
-version = "0.4.0"
+version = "0.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cmake 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
index 1658a1a1bec5f81b5e1952989eafbf564de90106..97a7f499afa2628af28fdf04bbbd17b5a7a2fbc2 100644 (file)
@@ -138,25 +138,6 @@ pub fn resolve_dependencies<'a>(root_package: &Package,
     Ok((packages, resolved_with_overrides))
 }
 
-fn validate_target(package: &Package,
-                   name: &str,
-                   kind: TargetKind,
-                   kind_str: &str) -> CargoResult<()> {
-    let target = package.targets().iter().find(|t: &&Target| {
-        t.name() == name && *t.kind() == kind
-    });
-    if target.is_none() {
-        let suggestion = package.find_closest_target(name, kind);
-        match suggestion {
-            Some(s) => bail!("no {} target named `{}`\n\nDid you mean `{}`?",
-                             kind_str, name, s.name()),
-            None => bail!("no {} target named `{}`", kind_str, name),
-        }
-    }
-
-    Ok(())
-}
-
 pub fn compile_pkg<'a>(root_package: &Package,
                        source: Option<Box<Source + 'a>>,
                        options: &CompileOptions<'a>)
@@ -176,16 +157,6 @@ pub fn compile_pkg<'a>(root_package: &Package,
         bail!("jobs must be at least 1")
     }
 
-    if let CompileFilter::Only{bins, examples, ..} = *filter {
-        for bin in bins {
-            try!(validate_target(root_package, bin, TargetKind::Bin, "bin"));
-        }
-
-        for example in examples {
-            try!(validate_target(root_package, example, TargetKind::Example, "example"));
-        }
-    }
-
     let (packages, resolve_with_overrides) = {
         try!(resolve_dependencies(root_package, config, source, features,
                                   no_default_features))
@@ -392,7 +363,14 @@ fn generate_targets<'a>(pkg: &'a Package,
                         });
                         let t = match target {
                             Some(t) => t,
-                            None => bail!("no {} target named `{}`", desc, name),
+                            None => {
+                                let suggestion = pkg.find_closest_target(name, kind);
+                                match suggestion {
+                                    Some(s) => bail!("no {} target named `{}`\n\nDid you mean `{}`?",
+                                                     desc, name, s.name()),
+                                    None => bail!("no {} target named `{}`", desc, name),
+                                }
+                            }
                         };
                         debug!("found {} `{}`", desc, name);
                         targets.push((t, profile));